package com.zhl.multi_data_source_demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 封装的对数据源进行操作的类：
 */
public class DataSourceHolder {
    private static Logger logger = LoggerFactory.getLogger(DataSourceAspect.class);
    //线程  本地环境
    private static final ThreadLocal<String> dataSources = new InheritableThreadLocal();

    //设置数据源
    public static void setDataSource(String datasource) {
        logger.info("设置数据源={}", datasource);
        dataSources.set(datasource);
    }

    //获取数据源
    public static String getDataSource() {
        return  dataSources.get();
    }

    //清除数据源
    public static void clearDataSource() {
        dataSources.remove();
    }

}
